package com.jumi.microservice.controller.admin;

import com.alibaba.excel.EasyExcel;
import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ExportExcelCommonResponse;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.constant.RequestConstant;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.dto.compensation.*;
import com.jumi.microservice.service.admin.AdminCompensationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author Scw
 * @Date 2020-08-21 14:54
 */
@Api(tags = {"后台售后管理--补偿管理相关接口"})
@RestController
@RequestMapping("/admin/compensation")
public class CompensationController extends BaseController {
    @Resource
    private AdminCompensationService adminCompensationService;

    @PostMapping(value = "/addCompensation")
    @ApiOperation("补偿添加")
    public ResponseResult<Boolean> addCompensation(CompensationAddRequest compensationAddRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        compensationAddRequest.setOperatorId(getUid());
        compensationAddRequest.setOperatorName(getUserName());
        result.setData(adminCompensationService.addCompensation(compensationAddRequest));
        return result;
    }

    @PostMapping(value = "/agreeCompensation")
    @ApiOperation("补偿审核同意")
    public ResponseResult<Boolean> agreeCompensation(CompensationRequest compensationRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        compensationRequest.setOperatorId(getUid());
        compensationRequest.setOperatorName(getUserName());
        result.setData(adminCompensationService.agreeCompensation(compensationRequest));
        return result;
    }

    @PostMapping(value = "/batchAgreeCompensation")
    @ApiOperation("补偿审核批量同意")
    public ResponseResult<Boolean> batchAgreeCompensation(CompensationBatchRequest compensationBatchRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        compensationBatchRequest.setOperatorId(getUid());
        compensationBatchRequest.setOperatorName(getUserName());
        result.setData(adminCompensationService.batchAgreeCompensation(compensationBatchRequest));
        return result;
    }

    @PostMapping(value = "/refuseCompensation")
    @ApiOperation("补偿审核拒绝")
    public ResponseResult<Boolean> refuseCompensation(CompensationCheckRequest compensationCheckRequest, CompensationRequest compensationRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        compensationRequest.setOperatorId(getUid());
        compensationRequest.setOperatorName(getUserName());
        result.setData(adminCompensationService.refuseCompensation(compensationCheckRequest, compensationRequest));
        return result;
    }

    @PostMapping(value = "/compensationInfo")
    @ApiOperation("补偿审核信息")
    public ResponseResult<CompensationInfoResponse> compensationInfo(CompensationRequest compensationRequest) {
        ResponseResult<CompensationInfoResponse> result = new ResponseResult<>();
        result.setData(adminCompensationService.compensationInfo(compensationRequest));
        return result;
    }

    @GetMapping("/afterSale/dictionary")
    @ApiOperation("售后类型对照字典")
    public ResponseResult<Map<Integer, String>> getAfterSale() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminCompensationService.getAfterSale());
        return result;
    }

    @GetMapping("/checkStatus/dictionary")
    @ApiOperation("审核状态对照字典")
    public ResponseResult<Map<Integer, String>> getCheckStatus() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminCompensationService.getCheckStatus());
        return result;
    }

    @GetMapping("/compensationList")
    @ApiOperation("全部列表")
    TableDataInfo<CompensationListResponse> compensationList(CompensationListRequest compensationListRequest) {
        return adminCompensationService.compensationList(compensationListRequest);
    }

    @GetMapping("/compensationCheckList")
    @ApiOperation("待审核列表")
    TableDataInfo<CompensationCheckListResponse> compensationCheckList(CompensationListRequest compensationListRequest) {
        return adminCompensationService.compensationCheckList(compensationListRequest);
    }

    @GetMapping("/compensationAgreeList")
    @ApiOperation("已同意列表")
    TableDataInfo<CompensationAgreeListResponse> compensationAgreeList(CompensationStepListRequest compensationStepListRequest) {
        return adminCompensationService.compensationAgreeList(compensationStepListRequest);
    }

    @GetMapping("/compensationRefuseList")
    @ApiOperation("已拒绝列表")
    TableDataInfo<CompensationRefuseListResponse> compensationRefuseList(CompensationStepListRequest compensationStepListRequest) {
        return adminCompensationService.compensationRefuseList(compensationStepListRequest);
    }

    @PostMapping("/exportExcel")
    @ApiOperation("全部导出excel")
    public void exportExcel(ExportCompensationRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportCompensationResponse> exportCompensationResponseExportExcelCommonResponse = adminCompensationService.exportExcel(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportCompensationResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportCompensationResponse.class).sheet("sheet1").doWrite(exportCompensationResponseExportExcelCommonResponse.getData());
    }

    @PostMapping("/exportExcelCheck")
    @ApiOperation("待审核导出excel")
    public void exportExcelCheck(ExportCompensationRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportCompensationResponse> exportCompensationResponseExportExcelCommonResponse = adminCompensationService.exportExcelCheck(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportCompensationResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportCompensationResponse.class).sheet("sheet1").doWrite(exportCompensationResponseExportExcelCommonResponse.getData());
    }

    @PostMapping("/exportExcelAgree")
    @ApiOperation("已同意导出excel")
    public void exportExcelAgree(ExportCompensationStepRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportCompensationResponse> exportCompensationResponseExportExcelCommonResponse = adminCompensationService.exportExcelAgree(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportCompensationResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportCompensationResponse.class).sheet("sheet1").doWrite(exportCompensationResponseExportExcelCommonResponse.getData());
    }

    @PostMapping("/exportExcelRefuse")
    @ApiOperation("已拒绝导出excel")
    public void exportExcelRefuse(ExportCompensationStepRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportCompensationResponse> exportCompensationResponseExportExcelCommonResponse = adminCompensationService.exportExcelRefuse(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportCompensationResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportCompensationResponse.class).sheet("sheet1").doWrite(exportCompensationResponseExportExcelCommonResponse.getData());
    }

    @GetMapping("/aliPayTransferQuery")
    @ApiOperation("企业支付宝打款查询")
    public ResponseResult<String> aliPayTransferQuery(AliPayTransferQueryRequest aliPayTransferQueryRequest) {
        ResponseResult<String> result = new ResponseResult<>();
        result.setData(adminCompensationService.aliPayTransferQuery(aliPayTransferQueryRequest));
        return result;
    }
}
